from fastapi_redis_demo.app.redis_client import RedisSingleton

class UserService:
    @staticmethod
    async def get_user(user_id: str):
        """从 Redis 获取用户数据"""
        redis_client = await RedisSingleton.get_client()
        key = f"user:{user_id}"
        user_data = await redis_client.get(key)
        return user_data

    @staticmethod
    async def set_user(user_id: str, name: str):
        """存储用户数据到 Redis"""
        redis_client = await RedisSingleton.get_client()
        key = f"user:{user_id}"
        await redis_client.set(key, name, ex=3600)  # 60秒过期
        return {"user_id": user_id, "name": name}